// protobuf 序列化/反序列化测试代码
#include <iostream>
#include "fast_start.pb.h"

int main()
{
    // 实例化people
    contacts::PeopleInfo people_1;
    people_1.set_name("张三");
    people_1.set_age(18);

    // 序列化
    std::string Ser_str; // 存放序列化结果
    bool ret = people_1.SerializeToString(&Ser_str);
    if (!ret)
    {
        std::cerr << "序列化失败！" << std::endl;
    }
    // protobuf 序列化后的结果是二进制的，所以打印出来结果不可预测
    std::cout << "序列化成功！结果：" << Ser_str << std::endl;
    std::cout << "################################"<<std::endl;

    // 反序列化
    // 实例化一个people对象
    contacts::PeopleInfo people_2;
    ret = people_2.ParseFromString(Ser_str);
    if (!ret)
    {
        std::cerr << "反序列化失败！" << std::endl;
    }
    std::cout<<"反序列化成功！"<<std::endl;
    std::cout<<"姓名："<<people_2.name()<<std::endl;
    std::cout<<"年龄："<<people_2.age()<<std::endl;

    return 0;
}